package exercises.leetcode;

/**
 * <a href="">
 * </a>
 *
 * <p><span color="#87CEEB">描述:</span>
 *
 * @author or2
 * @date 2021年11月14日 时间: 11:28
 */
public class No5928 {
    public String decodeCiphertext(String encodedText, int rows) {
        if (rows == 1) return encodedText;

        boolean blank = true;
        int length = encodedText.length();
        int colLen = length / rows;

        var sb = new StringBuilder();
        for (int i = 0; i < colLen; i++) {
            var aux = new StringBuilder();
            for (int j = i; j < length; j += colLen + 1) aux.append(encodedText.charAt(j));
            if (!aux.toString().isBlank()) blank = false;
            if (blank) sb.append(aux);
        }

        return sb.toString().stripTrailing();
    }
}
